import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:loading_indicator/loading_indicator.dart';

class Loading {
  static Loading? _instance;

  // 私有的命名构造函数
  Loading._internal();

  static Loading getIns() {
    if (_instance == null) {
      _instance = Loading._internal();

      EasyLoading.instance
        ..displayDuration = const Duration(milliseconds: 2000)
        ..indicatorType = EasyLoadingIndicatorType.fadingCircle
        ..loadingStyle = EasyLoadingStyle.dark
        ..indicatorSize = 45.0
        ..radius = 10.0
        ..progressColor = Colors.yellow
        ..backgroundColor = Colors.green
        ..indicatorColor = Colors.yellow
        ..textColor = Colors.yellow
        ..maskColor = Colors.blue.withOpacity(0.5)
        ..userInteractions = false
        ..indicatorType = EasyLoadingIndicatorType.ring
        ..dismissOnTap = false;

    }

    return _instance!;
  }

  void loading({msg = String}) {
    ///先关闭弹窗状态
    hide();
    ///再显示弹窗
    EasyLoading.show(status: msg);
  }

  void success({msg = String}) {
    ///先关闭弹窗状态
    hide();
    ///再显示弹窗
    EasyLoading.showSuccess(msg);
  }

  void info({msg = String}) {
    ///先关闭弹窗状态
    hide();
    ///再显示弹窗
    EasyLoading.showInfo(msg);
  }

  void msg({msg = String}) {
    ///先关闭弹窗状态
    hide();
    ///再显示弹窗
    EasyLoading.showToast(msg);
  }

  void hide() {
    EasyLoading.dismiss();
  }

}
